<!doctype html>
<p><span style="font-size: 500%; color: red;">  [!(5)#]</span>9abcdefghi</p>
<script>
const selection = window.getSelection();
const sample = document.querySelector('p');
// Select "(5)"
selection.collapse(sample.firstChild.firstChild, 4);
selection.extend(sample.firstChild.firstChild, 7);
</script>
